#include "graph.h"
#include<bits/stdc++.h>
using namespace std;
const int N=210;
int ans[N];
vector<int> p1[N],p2[N]; //从根到x的路径和从x到根的路径
int d[N];
bool book[N];
int n=200;
void walk(int x,int y)
{
    if(x==y) return ;
    int p=0;
    while(p<p1[x].size()&&p<p1[y].size()&&p1[x][p]==p1[y][p]) p++;
    for(int i=(int)p2[x].size()-1;i>=p;i--) Move(p2[x][i],Color());
    for(int i=p;i<p1[y].size();i++) Move(p1[y][i],Color());
}
void work()
{
    for(int i=1;i<=n;i++) p1[i].clear(),p2[i].clear(),d[i]=book[i]=0;
    int cnt=0;
    queue<int> q;
    int now=1;
    q.push(++cnt);
    while(q.size())
    {
        int x=q.front();
        q.pop();
        walk(now,x),now=x;
        if(!book[x]) ans[d[x]]++;
        int D=NumberOfRoads();
        for(int i=1;i<=D;i++)
        {
            Move(i,2);
            if(Color()!=2) 
            {
                q.push(++cnt);
                book[cnt]=Color()==3;
                d[cnt]=d[x]+1;
                p1[cnt]=p1[x],p1[cnt].push_back(i);
                p2[cnt]=p2[x],p2[cnt].push_back(LastRoad());
            }
            Move(LastRoad(),2);
        }
    }
    for(int i=cnt;i;i--)
    {
        walk(now,i),now=i;
        Move(1,book[i]?3:1),Move(LastRoad(),Color());
    }
}
void dfs1()
{
    int c=Color();
    if(c==3) return ;
    work(); 
    int D=NumberOfRoads();
    for(int i=1;i<=D;i++)
    {
        Move(i,3);
        int t=LastRoad();
        dfs1();
        Move(t,3);
    }
}
void Inspect(int R) 
{
    dfs1(); 
    for(int i=1;i<=R;i++) Answer(i,ans[i]);  
}
